<?php

/**
 * Класс по переводу полей Кинопоиска в названия полей в БД
 *
 * @author Di_Moon
 */
class fieldsConvertor {
    protected $fields = array();
    
    function __construct() { 
        $fields["год"] = "year";
        $fields["страна"] = "country";
        $fields["слоган"] = "slogan";
        $fields["режиссер"] = "director";
        $fields["сценарий"] = "scenario";
        $fields["продюсер"] = "producer";
        $fields["оператор"] = "operator";
        $fields["композитор"] = "composer";
        $fields["художник"] = "painter";
        $fields["монтаж"] = "assembly";
        $fields["жанр"] = "genre";
        $fields["бюджет"] = "budget";
        $fields["сборы в США"] = "charges_usa";
        $fields["сборы в мире"] = "charges_world";
        $fields["сборы в России"] = "charges_russia";
        $fields["зрители"] = "audience";
        $fields["премьера (мир)"] = "premiere_world";
        $fields["премьера (РФ)"] = "premiere_russia";
        $fields["релиз на dvd"] = "release_dvd";
        $fields["релиз на blu-ray"] = "release_br";
        $fields["возраст"] = "age";
        $fields["рейтинг mpaa"] = "age_mpaa";
        $fields["время"] = "time";
        
        foreach($fields as $field=>$value) {
            $field = $this->fieldToLower($field);
            $this->fields[$field] = $value;
        }
    }
    
    function fieldToLower($fld1) {
        $fld1 = strtolower(iconv("utf-8", "windows-1251", $fld1));
        return $fld1;
    }
    
    function convert($table) {
        $rv = array();
        foreach($this->fields as $key=>$value) {
            $rv[$this->fields[$key]] = "n/a";
        }
        foreach($table as $field=>$value) {
            $field = $this->fieldToLower($field);
            if(isset($this->fields[$field]))
                $rv[$this->fields[$field]] = $value;
        }
        
        return $rv;
    }
}

?>
